import React, {Component} from 'react';
import PropTypes from 'prop-types';

class Child extends Component{
    render(){
        console.log(this.props.text)
        return(<div>
            123456
        </div>)
    }
}

class StateVsProps extends Component {
    state={
        text:'123456'
    }
    render() {
        return (
            <div>
                <button onClick={()=>{
                    let text="changcun";
                    this.setState({
                        text:text
                    })

                }}>修改</button>
                <Child text={this.state.text} ></Child>
            </div>
        );
    }
}

/*
* 属性在子组件属于只读属性，无法修改
* */

StateVsProps.propTypes = {
    id:PropTypes.number
};

export default StateVsProps;
